package org.example;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
        Class<?> clazz = Student.class;
        Student student = (Student) clazz.getConstructor(int.class).newInstance(10);//创建对象
        student.test();
        Field fi = clazz.getDeclaredField("a");//获取对应的属性

        Field modifiers = Field.class.getDeclaredField("modifiers");//获取modifiers对象
        modifiers.setAccessible(true);
        modifiers.setInt(fi,fi.getModifiers()&~Modifier.FINAL);//去除属性的final属性

        fi.setAccessible(true);
        fi.setInt(student,100);//访问修改对象的属性值
        student.test();
    }

    static class Student{
        private final int a;
        public Student(int a){
            this.a = a;
        }

        public void test(){
            System.out.println(this.a);
        }
    }
    public static void main1(String[] args) {
        Integer i = 10;
        for (Class<?> anInterface : i.getClass().getInterfaces()) {//获取当前类实现接口
            System.out.println(anInterface.getName());
        }

        for (Type genericInterface : i.getClass().getGenericInterfaces()) {//获取
            System.out.println(genericInterface.getTypeName());
        }
    }
}
